package etf.tests;

import etf.db40.ComplexDb4o;
import etf.hibernate.ComplexHibernate;
import etf.jdbc.ComplexJDBC;


public class ComplexTest extends Test{
	
	private ComplexDb4o 		db4o;
	private ComplexHibernate 	hibernate;
	private ComplexJDBC 		jdbc;
	private int inserts[] ={50000};
	
	public ComplexTest(){
		db4o 		= new ComplexDb4o("ComplexTest");
		hibernate 	= new ComplexHibernate();
		jdbc 		= new ComplexJDBC();
	}
	
	public void firstTest(){
		
		for (int i = 0; i < inserts.length; i++){
//			clearDB();
//			inserts(inserts[i]);
//			queryOne(inserts[i]);
//			queryTwo(inserts[i]);
//			queryThree(inserts[i]);
//			queryFour(inserts[i]);
			update(inserts[i]);
		}
	}
	
	private void inserts(int p){
		printSeparator(0);
		System.out.println("       SLOZENI INSERT");
		printSeparator(50);
//		System.out.println("Db40           : " + db4o.insert(p) + " ms");
//		System.out.println("Hibernate/MySQL: " + hibernate.insert(p) + " ms");
//		System.out.println("JDBC/MySQL     : " + jdbc.insert(p) + " ms");
	}
	
	private void queryOne(int p){
		printSeparator(50);
		System.out.println("       SLOZENI QUERY I");
		printSeparator(50);
		System.out.println("Db40           : " + db4o.queryOne(p) + " ms");
		System.out.println("Hibernate/MySQL: " + hibernate.queryOne(p) + " ms");
		System.out.println("JDBC/MySQL     : " + jdbc.queryOne(p) + " ms");
	}
	
	private void queryTwo(int p){
		printSeparator(50);
		System.out.println("       SLOZENI QUERY II");
		printSeparator(50);
		System.out.println("Db40           : " + db4o.queryTwo(p) + " ms");
		System.out.println("Hibernate/MySQL: " + hibernate.queryTwo(p) + " ms");
		System.out.println("JDBC/MySQL     : " + jdbc.queryTwo(p) + " ms");
	}
	
	private void queryThree(int p){
		printSeparator(50);
		System.out.println("       SLOZENI QUERY III");
		printSeparator(50);
		System.out.println("Db40           : " + db4o.queryThree(p) + " ms");
		System.out.println("Hibernate/MySQL: " + hibernate.queryThree(p) + " ms");
		System.out.println("JDBC/MySQL     : " + jdbc.queryThree(p) + " ms");
	}
	
	private void queryFour(int p){
		printSeparator(50);
		System.out.println("       SLOZENI QUERY IV");
		printSeparator(50);
		System.out.println("Db40           : " + db4o.queryFour(p) + " ms");
		System.out.println("Hibernate/MySQL: " + hibernate.queryFour(p) + " ms");
		System.out.println("JDBC/MySQL     : " + jdbc.queryFour(p) + " ms");
	}
	
	private void update(int p){
		printSeparator(50);
		System.out.println("       SLOZENI UPDATE");
		printSeparator(50);
		System.out.println("Db40           : " + db4o.update(p) + " ms");
		System.out.println("Hibernate/MySQL: " + hibernate.update(p) + " ms");
		System.out.println("JDBC/MySQL     : " + jdbc.update(p) + " ms");
	}
	
	private void clearDB(){
//		hibernate.clearDB();
		jdbc.clearDB();
	}
	
	public void closeSessions(){
		db4o.closeDatabase();
		hibernate.closeDatabase();
		jdbc.closeDatabase();
	}
}
